| Total Complexity | 12 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { execute } from "../../compiler/func"; |
||
| 2 | export class npm { |
||
| 3 | static args = []; |
||
| 4 | /** |
||
| 5 | * Install package |
||
| 6 | * @param pkg |
||
| 7 | */ |
||
| 8 | static install(pkg: string | any[]) { |
||
| 9 | if (typeof pkg == "string") { |
||
| 10 | this.args.push({ install: pkg }); |
||
| 11 | } else if (Array.isArray(pkg)) { |
||
| 12 | pkg.forEach(function (item) { |
||
| 13 | npm.args.push({ install: item }); |
||
| 14 | }); |
||
| 15 | } |
||
| 16 | this.run(); |
||
| 17 | return this; |
||
| 18 | } |
||
| 19 | |||
| 20 | static timer_run: any = null; |
||
| 21 | static run() { |
||
| 22 | if (this.args && this.args.length) { |
||
| 23 | if (this.timer_run) { |
||
| 24 | clearTimeout(this.timer_run); |
||
| 25 | } |
||
| 26 | setTimeout(function () { |
||
| 27 | npm.timer_run = setTimeout(function () { |
||
| 28 | npm.run(); |
||
| 29 | }, 3000); |
||
| 30 | }, 200); |
||
| 31 | if (this.running) { |
||
| 32 | return; |
||
| 33 | } |
||
| 34 | var args = this.args[0]; |
||
| 35 | if (typeof args == "object") { |
||
| 36 | for (const key in args) { |
||
| 37 | if (args.hasOwnProperty(key)) { |
||
| 38 | if (typeof key == "string" && typeof args[key] == "string") { |
||
| 39 | console.log("npm", args); |
||
| 40 | npm.npm([key, args[key]]); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | this.args.shift(); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | private static running = null; |
||
| 50 | static npm(args: string[]) { |
||
| 51 | execute(`npm ${args.join(" ")}`); |
||
| 52 | } |
||
| 54 |